ContractCloseView = Ext.extend(Ext.Panel, {
	constructor : function(a) {
		Ext.applyIf(this, a);
		this.initUIComponents();
		ContractCloseView.superclass.constructor.call(this, {
			id : "ContractCloseView",
			title : "合同关闭",
			iconCls : "menu-productionPlanCoating",
			layout : "border",
			autoScroll : true
		});
	},
	initUIComponents : function() {
		this.initSearchPanel();
		this.initGridPanel();
		this.items = [ this.searchPanel, this.gridPanel ];
	},
	onSearch : function(c) {
		var a = Ext.getCmp("ContractCloseSearchForm");
		var b = Ext.getCmp("ContractCloseGrid");
		if (a.getForm().isValid()) {
			$search({
				searchPanel : a,
				gridPanel : b
			});
		}
	}
});
ContractCloseView.prototype.initSearchPanel = function() {
	this.searchPanel = new Ext.FormPanel({
		region : "north",
		height : 35,
		frame : false,
		border : false,
		id : "ContractCloseSearchForm",
		layout : "hbox",
		layoutConfig : {
			padding : "5",
			align : "right" 
		},
		bodyStyle:"margin-right: 10px;",
		defaults : {
			xtype : "label",
			border : false,
			margins : {
				top : 0,
				right : 4,
				bottom : 4,
				left : 4
			}
		},
		items : [ 
		        {
		 			text : "合同名称"
		 		}, {
		 			xtype : "textfield",
		 			name : "Q_contractName_S_LK"
		 		}, 
		 		
		 		
		{
			xtype : "button",
			text : "查询",
			iconCls : "search",
			scope : this,
			handler : this.onSearch.createCallback(this)
		}, {
			xtype : "button",
			text : "清空",
			scope : this,
			iconCls : "reset",
			handler :ContractCloseView.reset
		}  ]
	});
};
ContractCloseView.prototype.initGridPanel = function() {
	var b = new Ext.data.Store({
		proxy : new Ext.data.HttpProxy({
			url : __ctxPath + "/contract/verifyListContract.do"
			}),
		reader : new Ext.data.JsonReader({
			root : "result",
			totalProperty : "totalCounts",
			fields : [ {
				name : "contractId",
				type : "long"
			}, "contractNo", "contractName", "contractAmount",
			 "projectName", "contractState"
					  ]
		}),
		remoteSort : true
	});
	b.setDefaultSort("contractId", "asc");
	b.load({
		params : {
			start : 0,
			limit : 25
		}
	});
	var e = new Ext.grid.CheckboxSelectionModel();
	var a = new Ext.grid.ColumnModel(
			{
				columns : [
				           					e,
											new Ext.grid.RowNumberer(),
											{
												header : "contractId",
												dataIndex : "contractId",
												hidden : true
											},
											{
												header : "合同编号",
												dataIndex : "contractNo"
											},
											{
												header : "合同名称",
												dataIndex : "contractName"
											},
											{
												header : "合同金额",
												dataIndex : "contractAmount",
												renderer : function(c) {
													return c + "元";
												}
											},
											{
												header : "所属项目",
												dataIndex : "projectName"
												
											},
//											{
//												header : "创建人",
//												dataIndex : "creator"
//											},
//											{
//												header : "创建时间",
//												dataIndex : "createTime"
//											},
											{
												header : "合同状态",
												dataIndex : "contractState",
												width : 80,
												renderer : function(f) {
													if (f == null) {
														return "<font color='red'><b>未查询到状态</b></font>";
													} else {
														if(f<2){
															return "<b>正常</b>";
														}
														if(f>=2){
															return "<font color='red'><b>已关闭</b></font>";									
														}
														
													}
												}
											},
											{
												header : "管理",
												dataIndex : "contractId",
												sortable : true,
												width : 40,
												renderer : function(j, i, g, m, h) {
													var l = g.data.contractId;
													var f = g.data.pplName;
													var state=g.data.contractState;var k = "";
													if (l != -1) {
														if(state==1){
															if (isGranted("_ContractVerify")) {
																k += '&nbsp;<button title="编辑" value=" " class="btn-edit" onclick="ContractCloseView.edit('
																		+ l
																		+ ",'"
																		+ f
																		+ "')\"></button>";
															}
														}else{
																k += '<button title="查看" value="" class="btn-showDetail" onclick="ContractCloseView.show('
																	+ l
																	+ ",'"
																	+ f
																	+ "')\"></button>";
														}
													}
													return k;
												}
											} ],
											defaults : {
												sortable : true,
												menuDisabled : true,
												width : 100
											}
										});
	this.gridPanel = new Ext.grid.GridPanel({
		id : "ContractCloseGrid",
		tbar : this.toolbar,
		store : b,
		region : "center",
		shim : true,
		trackMouseOver : true,
		disableSelection : false,
		loadMask : true,
		cm : a,
		sm : e,
		viewConfig : {
			forceFit : true,
			enableRowBody : false,
			showPreview : false
		},
		bbar : new HT.PagingBar({
			store : b
		})
	});
};




/*ContractCloseView.remove = function(b) {
	var a = Ext.getCmp("ContractCloseGrid");
	Ext.Msg.confirm("信息确认", "您确认要删除该记录吗？", function(c) {
		if (c == "yes") {
			Ext.Ajax.request({
				url : __ctxPath + "/contract/multiDelContractClose.do",
				params : {
					ids : b
				},
				method : "post",
				success : function(response) {
					var result=Ext.util.JSON.decode(response.responseText);
					if(result.success){
						Ext.ux.Toast.msg("信息", "成功删除所选记录！");
					}else{
						Ext.MessageBox.show({
							title : "操作提示",
							msg : result.msg?result.msg:"删除信息出错，请联系管理员！",
							buttons : Ext.MessageBox.OK,
							icon : "ext-mb-error"
						});
					}
					a.getStore().reload({
						params : {
							start : 0,
							limit : 25
						}
					});
				}
			});
		}
	});

};*/

ContractCloseView.reset = function() {
	var a = Ext.getCmp("ContractCloseSearchForm");
	a.getForm().reset();
};

ContractCloseView.edit = function(a) { 
	new ContractCloseForm({
		contractId:a
	}).show();
};
ContractCloseView.show = function(a) { 
	new ContractCloseShow({
		contractId:a
	}).show();
};
/*ContractCloseView.remove = function() {
	var h = Ext.getCmp("ContractCloseGrid");
	var f = h.getSelectionModel().getSelections();
	if (f.length == 0) {
		Ext.ux.Toast.msg("信息", "请选择要删除的记录！");
		return;
	}
	var j = Array(); 
	for ( var g = 0; g < f.length; g++) { 
		 j.push(f[g].data.ppfId); 
	}
	ContractCloseView.remove(j);
};*/